#include <stdio.h>

#include "md5.h"


void test_md5_str(const char *input_str, const char *expect_str);

int main()
{

    test_md5_str( "", "d41d8cd98f00b204e9800998ecf8427e");
    test_md5_str("a", "0cc175b9c0f1b6a831c399e269772661");
    test_md5_str("abc",  "900150983cd24fb0d6963f7d28e17f72");
    test_md5_str("message digest", "f96b697d7cb7938d525a2f31aaf161d0");
    test_md5_str("abcdefghijklmnopqrstuvwxyz", "c3fcd3d76192e4007dfb496cca67e13b");
    test_md5_str("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", "d174ab98d277d9f5a5611c2c9f419d9f");
    test_md5_str("12345678901234567890123456789012345678901234567890123456789012345678901234567890", "57edf4a22be3c955ac49da2e2107b67a");

    return 0;
}


void test_md5_str(const char *input_str, const char *expect_str)
{
    static md5_byte_t digest[16];
    static char out_str[33];
    out_str[32] = '\0';

    md5_string(input_str, digest);
    int i;
    for ( i = 0; i < 16; ++i) {
        sprintf(out_str + i * 2, "%02x", digest[i]);
    }

    if ( 0 != memcmp( out_str, expect_str, 32) ) {
        
        printf("%s md5 val is %s,  not same to %s\n", input_str, out_str, expect_str);
    }
}